package com.wx.business.course.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.eachonline.mapper.GenericMapper;
import com.eachonline.service.GenericServiceImpl;
import com.eachonline.util.UUIDUtil;
import com.wx.business.course.OrderRecordService;
import com.wx.business.util.OrderStatus;
import com.wx.dao.mapper.OrderRecordMapper;
import com.wx.model.OrderRecord;
import com.wx.model.OrderRecordExample;
@Service("orderRecord")
public class OrderRecordServiceImpl extends GenericServiceImpl<OrderRecord, OrderRecordExample, String> implements OrderRecordService  {

	private static final  Logger logger =Logger.getLogger(OrderRecordServiceImpl.class);

	@Resource
	private OrderRecordMapper orderRecordMapper;
	
	@Override
	protected GenericMapper<OrderRecord, OrderRecordExample, String> getGenericMapper() {
		return orderRecordMapper;
	}

	@Override
	public OrderRecord createOrder(String sellerId, String buyerId,String goodsId , String goodsPic,String orderNo, String arcName, String orderName, String orderDesc,
			double goodsFee, double orderFee) {
		// TODO Auto-generated method stub
		
		OrderRecord orderRecord=new OrderRecord();
		orderRecord.setSid(UUIDUtil.getUUID());
		orderRecord.setArcName(arcName);
		orderRecord.setGoodsPic(goodsPic);
		orderRecord.setBuyerId(buyerId);
		orderRecord.setSellerId(sellerId);
		orderRecord.setOrderNo(orderNo);
		orderRecord.setGoodsFee(goodsFee);
		orderRecord.setOrderFee(orderFee);
		orderRecord.setGoodsId(goodsId);
		orderRecord.setOrderDesc(orderDesc);
		orderRecord.setOrderStatus(OrderStatus.ORDER_PAY);
		orderRecord.setGoodsPic(goodsPic);
		orderRecordMapper.insertSelective(orderRecord);
		return orderRecord;
	}

	@Override
	public void changeOrderStatus(String orderNo, String userId, int status) {
		// TODO Auto-generated method stub
		OrderRecordExample ext=new OrderRecordExample();
		ext.createCriteria().andOrderNoEqualTo(orderNo).andBuyerIdEqualTo(userId);
		List<OrderRecord> orderList=orderRecordMapper.selectByExample(ext);
		;
		if(!orderList.isEmpty())
		{
			OrderRecord order=orderList.get(0);
			order.setOrderStatus(status);
			orderRecordMapper.updateByPrimaryKey(order);
		}
	}

	@Override
	public Map<String, Object> selectOrderMapById(String sid) {
		// TODO Auto-generated method stub
		return orderRecordMapper.selectOrderMapBySid(sid);
	}

	
}
